<template>
  <div>
    <van-datetime-picker
      v-model="currentDate"
      type="date"
      title="选择年月日"
      :min-date="minDate"
      :max-date="maxDate"
      @confirm="onClickRight"
      @consile="onClickLeft"
    />
  </div>
</template>

<script>
import dayjs from '@/utils/dayjs'
import { setUserInfoAPI } from '@/api'
export default {
  props: {
    birthday: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      minDate: new Date(1900, 0, 1),
      maxDate: new Date(),
      currentDate: new Date(this.birthday)
    }
  },
  methods: {
    onClickLeft() {
      this.$emit('close')
    },
    async onClickRight() {
      const birthday = dayjs(this.currentDate).format('YYYY-MM-DD')
      await setUserInfoAPI({
        birthday
      })
      this.$emit('update:birthday', birthday)
      this.$emit('close')
    }
  }
}
</script>

<style></style>